//1022. 从根到叶的二进制数之和
//思路：后序遍历的思想

#include <stdio.h>
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};

int dfs(struct TreeNode* root, int val)
{
    if(NULL == root)
        return 0;
    
    val = (val << 1) | root->val;
    if(NULL == root->left && NULL == root->right)
        return val;
    
    return dfs(root->left, 0) + dfs(root->right, 0);
};
int sumRootToLeaf(struct TreeNode* root){  
    return dfs(root, 0);
}